import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.pylab import *
import warnings
warnings.filterwarnings('ignore')

all_df=pd.read_csv('train_titanic.csv')

print(all_df['SibSp'].value_counts())

print(all_df['Parch'].value_counts())

all_df['family_count']=all_df['SibSp']+all_df['Parch']+1

print(all_df['family_count'].value_counts())

def a(x):
    if x==1:
        return '小'
    elif x==2 or x==3:
        return '中'
    else :return '大'

all_df['family_type']=all_df['family_count'].apply(a)
print(all_df['family_type'].value_counts())

import seaborn as sns
mpl.rcParams['font.sans-serif'] = ['SimHei']
sns.countplot(data=all_df,x='family_type',hue='Survived',order=['小','中','大'],hue_order=[1,0])
plt.show()